# location of the AdoScript and curl/wget extensions - needs to be a file location and not db:\\ SETG sLocation:("D:\\") # 0. Get base information of map CC "Modeling" GET_ACT_MODEL SETL nCurrentModelID:(modelid) # get all necessary IDs of attributes to run the script CC "Core" GET_ATTR_ID classid:bp-model attrname:("Map center") SETL nMapCenterAttrID:(attrid) CC "Core" GET_ATTR_ID classid:bp-model attrname:("Map zoom") SETL nMapZoomAttrID:(attrid) CC "Core" GET_ATTR_ID classid:bp-model attrname:("Map width (px)") SETL nMapWidthAttrID:(attrid) CC "Core" GET_ATTR_ID classid:bp-model attrname:("Map height (px)") SETL nMapHeightAttrID:(attrid) CC "Core" GET_ATTR_ID classid:bp-model attrname:("Map file") SETL nMapURLAttrID:(attrid) CC "Core" GET_ATTR_VAL objid:(nCurrentModelID) attrid:(nMapHeightAttrID) SETL nMapHeightPX:(val) SETL nMapHeight:(val/ 96 * 2.54cm) CC "Core" GET_ATTR_VAL objid:(nCurrentModelID) attrid:(nMapWidthAttrID) SETL nMapWidthPX:(val) SETL nMapWidth:(val/ 96 * 2.54cm) CC "Core" GET_ATTR_VAL objid:(nCurrentModelID) attrid:(nMapZoomAttrID) SETL sMapZoom:(val) CC "Core" GET_ATTR_VAL objid:(nCurrentModelID) attrid:(nMapCenterAttrID) SETL sMapCenterValue:(val) CC "AdoScript" MSGWIN ("Searching for map center location at " + sMapCenterValue) #get tempfilename for longitude and latitude values CC "AdoScript" GET_TEMP_FILENAME SETL sXMLMapCenter:(filename) SYSTEM (sLocation + "wget.exe -O "+sXMLMapCenter+" \"http://nominatim.openstreetmap.org/search?q="+sMapCenterValue+"&format=json\"") #with-console-window CC "AdoScript" FREAD file:(sXMLMapCenter) SETL sMapLocationJSON:(text) CC "AdoScript" MSGWIN hide # 1. user selection which location to use, parse JSON and construct listbox SETL lMapLocations:(replall (replall (replall (sMapLocationJSON, "}]", ""), "[{", ""), "},{", "\n")) # only if more than 1 found IF (tokcnt (lMapLocations, "\n") > 1) { SETL lSelectionField:"" FOR sMapLocation in:(lMapLocations) sep:"\n" { SETL sTempLatString:(copy (sMapLocation, search(sMapLocation, "\"lat\":\"", 0)+7, -1)) SETL sLatString:(copy (sTempLatString, 0, search (sTempLatString, "\"", 0))) SETL sTempLongString:(copy (sMapLocation, search(sMapLocation, "\"lon\":\"", 0)+7, -1)) SETL sLongString:(copy (sTempLongString, 0, search (sTempLongString, "\"", 0))) SETL sTempDisplayNameString:(copy (sMapLocation, search(sMapLocation, "\"display_name\":\"", 0)+16, -1)) SETL sDisplayNameString:(copy (sTempDisplayNameString, 0, search (sTempDisplayNameString, "\"", 0))) SETL lSelectionField:(tokunion (lSelectionField, sDisplayNameString + ";"+ sLongString +";" + sLatString, "\n") } CC "AdoScript" LISTBOX entries:(lSelectionField) toksep:"\n" title:"Search results" oktext:"Ok" boxtext:"Choose the location to be used" IF (endbutton = "ok") { SETL sMapLocationJSON:("\"display_name\":\"" + token (selection, 0, ";") + "\", \"lat\":\"" + token (selection, 2, ";") + "\"lon\":\"" + token (selection, 1, ";") + "\"") } ELSE { EXIT } } ELSE { # if only one, reset the variable to the single one found! SETL sMapLocationJSON:(lMapLocations) } SETL sTempLatString:(copy (sMapLocationJSON, search(sMapLocationJSON, "\"lat\":\"", 0)+7, -1)) SETL sLatString:(copy (sTempLatString, 0, search (sTempLatString, "\"", 0))) SETL sTempLongString:(copy (sMapLocationJSON, search(sMapLocationJSON, "\"lon\":\"", 0)+7, -1)) SETL sLongString:(copy (sTempLongString, 0, search (sTempLongString, "\"", 0))) SETL sTempDisplayNameString:(copy (sMapLocationJSON, search(sMapLocationJSON, "\"display_name\":\"", 0)+16, -1)) SETL sDisplayNameString:(copy (sTempDisplayNameString, 0, search (sTempDisplayNameString, "\"", 0))) # Show user name and center location in long/lat CC "AdoScript" INFOBOX ("Your map is centered at " + sDisplayNameString +".\nLongitude: " + sLongString + "\nLatitude: " + sLatString) CC "AdoScript" MSGWIN ("Map is downloaded and constructed at " + sDisplayNameString) CC "AdoScript" GET_TEMP_FILENAME SETL sGeoLocationURL:(filename + ".png") # Invoke open street map service to trigger download of map SYSTEM (sLocation + "wget.exe -O "+sGeoLocationURL+" \"http://ojw.dev.openstreetmap.org/StaticMap/?lat="+sLatString+"&lon="+sLongString+"&z="+sMapZoom+"&w="+STR nMapWidthPX+"&h="+STR nMapHeightPX+"&show=1\"") #with-console-window # set the value for displaying the file CC "Core" SET_ATTR_VAL objid:(nCurrentModelID) attrid:(nMapURLAttrID) val:(sGeoLocationURL) # adjust drawing area in tool to have full width and height CC "Modeling" SET_DRAWING_AREA_SIZE w:(nMapWidth) h:(nMapHeight) CC "AdoScript" MSGWIN hide